package com.jetpackframework.virtualapk;

import android.content.ComponentName;
import android.content.Intent;
import android.os.RemoteException;

import com.jetpackframework.VirtualInterface;
import com.jetpackframework.virtual.VirtualApk;

import java.io.File;
import java.util.HashMap;

public class VirtualManager extends VirtualInterface.Stub {

    private static VirtualManager virtualManager;
    private HashMap<String,VirtualApk> apkHashMap;
    private VirtualManager(){
        apkHashMap = new HashMap<>();
    }
    public static synchronized VirtualManager getInstance() {
        if (virtualManager == null){
            virtualManager = new VirtualManager();
        }
        return virtualManager;
    }

    public VirtualApk getVirtualApk(String packageName) {
        return apkHashMap.get(packageName);
    }

    public void loadApk(File apkFile) {
        VirtualApk apk = new VirtualApk(apkFile);
        apkHashMap.put(apk.getPackageName(),apk);
    }


    @Override
    public void loadApk(String apkPath) throws RemoteException {
        File file = new File(apkPath);
        if (!file.exists() || file.isFile()){
            return;
        }
        File[] files = file.listFiles();
        if (files != null && files.length > 0){
            for (File apkFile : files){
                loadApk(apkFile);
            }
        }
    }

    @Override
    public void launchPlugin(ComponentName component) throws RemoteException {

    }

    @Override
    public void launchPluginByName(String pluginPackageName) throws RemoteException {

    }

    @Override
    public void launchPluginByIntent(Intent pluginIntent) throws RemoteException {

    }
}
